CONTENTS | INDEX | PREV | NEXT
rewind
NAME
rewind - seek filepointer to beginning of file
SYNOPSIS
#include <stdio.h>
void rewind(fp);
FILE *fp;
FUNCTION
rewind() rewinds the file to the beginning, equivalent to
fseek(fp, 0L, 0);.
NOTE
refer to the file_pointer manual page for general information
EXAMPLE
/*
* print a file 3 times
*/
#include <stdio.h>
main(ac, av)
int ac;
char **av;
{
FILE *fp;
int i;
char buf[256];
if (ac == 1) {
puts("Expected textfile argument");
exit(1);
}
fp = fopen(av[1], "r");
if (fp == NULL) {
printf("Unable to open %sn", av[1]);
exit(1);
}
for (i = 1; i <= 3; ++i) {
rewind(fp);
printf("PRINTING #%dn", i);
while (fgets(buf, sizeof(buf), fp))
fputs(buf, stdout);
}
return(0);
}
INPUTS
FILE *fp; file pointer to rewind
RESULTS
none
SEE ALSO
fseek, fgetpos, fsetpos